﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BusinessEntity;
using BusinessLogic;

namespace CentalineWeb
{
    public partial class MySheet : System.Web.UI.Page
    {
        private User _userinfo;
        protected void Page_Load(object sender, EventArgs e)
        {
            _userinfo = Session["user"] as User;
            if (!IsPostBack)
            {
                BindData();
            }
        }

        private void BindData()
        {
            var roleId = new UserManager().GetRoleIdByUserId(_userinfo.UserId);
            DataTable dt = null;
            switch (roleId)
            {
                case 1:
                    (Master.FindControl("lblTitle") as Label).Text = "所有工单";
                    dt = new VwManager().GetAllSheet();
                    break;
                case 2://维修人员
                    (Master.FindControl("lblTitle") as Label).Text = "我受理的工单";
                    gvSheet.Columns[5].Visible = false;
                    gvSheet.Columns[9].Visible = false;
                    dt = new VwManager().GetSheetsByRepairerId(_userinfo.UserId);
                    break;
                case 3://报修人员
                    (Master.FindControl("lblTitle") as Label).Text = "我提交的工单";
                    gvSheet.Columns[4].Visible = false;
                    gvSheet.Columns[9].Visible = false;
                    dt = new VwManager().GetSheetsByApllierId(_userinfo.UserId);
                    break;
            }
            gvSheet.DataSource = dt;
            gvSheet.DataBind();
        }

        protected void gvSheet_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "WorkOrder")
            {
                var order = e.CommandArgument.ToString();
                Response.Redirect("SheetDetail.aspx?workorder="+order);
            }
        }

        protected void gvSheet_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            gvSheet.PageIndex = e.NewPageIndex;
            BindData();
        }
    }
}